package spring.angularjs.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import spring.angularjs.domain.History;

@Repository
public class HistoryDAOImpl implements HistoryDAO {
	
	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public int addHistory(History history) {
		sessionFactory.getCurrentSession().save(history);
		return history.getId();
	}

	@Override
	public History getHistory(int id) {
		History history = (History) sessionFactory.getCurrentSession().get(History.class, id);
		return history;
	}

	@Override
	public boolean saveOrUpdate(History history) {
		sessionFactory.getCurrentSession().saveOrUpdate(history);
		return true;
	}

	@Override
	public List<History> histories() {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(History.class);
		return criteria.list();
	}

}
